package com.pig4cloud.pig.module.controller.commonInfo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.mybatis.page.PageUtils;
import com.pig4cloud.pig.common.mybatis.page.TableDataInfo;
import com.pig4cloud.pig.module.api.entity.commonInfo.CommonInfoOrder;
import com.pig4cloud.pig.module.service.commonInfo.ICommonInfoOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 跳蚤、易货商品的 订单Controller
 *
 * @author ruoyi
 * @date 2022-12-13
 */
@Validated
@Api(value = "跳蚤、易货商品的 订单控制器", tags = {"跳蚤、易货商品的 订单管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/commonInfo/order")
public class CommonInfoOrderController {

    private final ICommonInfoOrderService commonInfoOrderService;

    /**
     * 查询跳蚤、易货商品的 订单列表
     */
    @ApiOperation("查询跳蚤、易货商品的 订单列表")
    @PreAuthorize("@pms.hasPermission('module:commonInfoOrder:list')")
    @GetMapping("/list")
    public TableDataInfo<CommonInfoOrder> list(@Validated CommonInfoOrder commonInfoOrder) {
        QueryWrapper<CommonInfoOrder> qw = new QueryWrapper<>();

        TableDataInfo<CommonInfoOrder> td = PageUtils.buildDataInfo(commonInfoOrderService.page(PageUtils.buildPage(),qw));
        List<CommonInfoOrder> list = td.getData();
        return td;
    }

    /**
     * 导出跳蚤、易货商品的 订单列表
     */
    @ApiOperation("导出跳蚤、易货商品的 订单列表")
    @PreAuthorize("@pms.hasPermission('module:commonInfoOrder:export')")
    @SysLog("跳蚤、易货商品的 订单")
    @GetMapping("/export")
    public List export(@Validated CommonInfoOrder commonInfoOrder) {
        List<CommonInfoOrder> list = commonInfoOrderService.list();
        // ExcelUtil<CommonInfoOrder> util = new // ExcelUtil<CommonInfoOrder>(CommonInfoOrder.class);
        return  list;// util.exportExcel(list, "跳蚤、易货商品的 订单");
    }

    /**
     * 获取跳蚤、易货商品的 订单详细信息
     */
    @ApiOperation("获取跳蚤、易货商品的 订单详细信息")
    @PreAuthorize("@pms.hasPermission('module:commonInfoOrder:query')")
    @GetMapping("/{id}")
    public R<CommonInfoOrder> getInfo(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        CommonInfoOrder commonInfoOrder = commonInfoOrderService.getById(id);
        return R.ok(commonInfoOrder);
    }

    /**
     * 新增跳蚤、易货商品的 订单
     */
    @ApiOperation("新增跳蚤、易货商品的 订单")
    @PreAuthorize("@pms.hasPermission('module:commonInfoOrder:add')")
    @SysLog("跳蚤、易货商品的 订单")

    @PostMapping()
    public R<Void> add(@Valid @RequestBody CommonInfoOrder commonInfoOrder) {
        return R.okByRow(commonInfoOrderService.save(commonInfoOrder) ? 1 : 0);
    }

    /**
     * 修改跳蚤、易货商品的 订单
     */
    @ApiOperation("修改跳蚤、易货商品的 订单")
    @PreAuthorize("@pms.hasPermission('module:commonInfoOrder:edit')")
    @SysLog("跳蚤、易货商品的 订单")

    @PutMapping()
    public R<Void> edit(@Valid @RequestBody CommonInfoOrder commonInfoOrder) {
        return R.okByRow(commonInfoOrderService.updateById(commonInfoOrder) ? 1 : 0);
    }

    /**
     * 删除跳蚤、易货商品的 订单
     */
    @ApiOperation("删除跳蚤、易货商品的 订单")
    @PreAuthorize("@pms.hasPermission('module:commonInfoOrder:remove')")
    @SysLog("跳蚤、易货商品的 订单")
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")  @PathVariable Long[] ids) {
        return R.okByRow(commonInfoOrderService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
